package com.example.shiro_demo1.shiro;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;

/**
 * 自定义密码验证类
 * @author cxp
 * @version 1.0
 * @date 2019/7/1 14:29
 */
public class RetryLimitHashedCredentialsMatcher extends HashedCredentialsMatcher {
    /**
     * 自定义密码匹配验证方法
     * 只是在原有的密码验证基础之上添加了密码错误的异常
     * @param token
     * @param info
     * @return
     */
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        //调用父类的密码匹配验证方法
        boolean matches = super.doCredentialsMatch(token, info);
        System.out.println(matches);
        if(!matches){
            throw new IncorrectCredentialsException("密码错误");
        }
        return true;
    }
}
